import { ref } from 'vue';
import { getCamera } from '../three-utils';

type UseCameraParams = {
  onCameraChange?: (isUseFlyCamera: boolean) => void;
};

/**
 * 切换相机的公共逻辑
 * @returns
 */
export default function useCamera(data: UseCameraParams = {}) {
  const { onCameraChange } = data;
  const screenWidth = window.innerWidth;
  const screenHeight = window.innerHeight;
  /**
   * 默认
   */
  const orbitControlsCamera = getCamera(screenWidth, screenHeight);
  const flyCamera = getCamera(screenWidth, screenHeight);

  const isUseFlyCamera = ref(false);

  const handleSwitchFlyCamera = () => {
    isUseFlyCamera.value = !isUseFlyCamera.value;
    typeof onCameraChange === 'function' && onCameraChange(isUseFlyCamera.value);
  };

  const getOrbitControlsCamera = () => orbitControlsCamera;
  const getFlyCamera = () => flyCamera;

  return {
    getFlyCamera,
    isUseFlyCamera,
    handleSwitchFlyCamera,
    getOrbitControlsCamera,
  };
}
